package org.sixtynine.stock.entity;

/**
 * @author Thilan
 * this class handle sub sector data
 */

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.Size;

import org.hibernate.validator.constraints.NotEmpty;

@Entity
@Table(name = "SUB_SECTOR")
public class SubSector extends BaseEntity {

	private int id;

	@NotEmpty
	@Size(min = 3)
	private String name;

	@NotEmpty
	@Size(min = 2)
	private String code;
	private Sector sector;

	// private Set<Company> companySubSector = new HashSet<Company>(0);

	public SubSector() {
	}

	public SubSector(String name, String code , Sector sector) {
		this.name = name;
		this.code = code;
		this.sector = sector;
	}

	@Id
	@Column(name = "ID", unique = true, nullable = false)
	@GeneratedValue(strategy = GenerationType.AUTO)
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	@Column(name = "NAME", nullable = false, length = 30)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@ManyToOne
	@JoinColumn(name = "SECTOR_ID")
	public Sector getSector() {
		return sector;
	}

	public void setSector(Sector sector) {
		this.sector = sector;
	}

	@Column(name = "CODE", nullable = false, length = 30)
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	@Override
	public boolean equals(Object obj) {
		return (id == ((SubSector) obj).getId());
	}

	@Override
	public Object _getKey() {
		return code;
	}

	/*
	 * @ManyToMany
	 * 
	 * @JoinTable(name = "STUDENT_COURSE", joinColumns = { @JoinColumn(name =
	 * "STUDENT_ID") }, inverseJoinColumns = { @JoinColumn(name = "COURSE_ID")
	 * }) public Set<Company> getCompanySubSector() { return companySubSector; }
	 * 
	 * public void setCompanySubSector(Set<Company> companySubSector) {
	 * this.companySubSector = companySubSector; }
	 */
}
